//
//  PersonCenterHeadView.m
//  HeWeiZhiNeng
//
//  Created by 林建 on 17/12/1.
//  Copyright © 2017年 YanCeyMichael.github.io. All rights reserved.
//

#import "PersonCenterHeadView.h"

@implementation PersonCenterHeadView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = Color.theme;
        //头像背景
        self.backImageView = [UIImageView new];
        [self addSubview:self.backImageView];
        [self CreatNewImageView:self.backImageView imageName:@"porfile-img_kuang" radius:50 enabled:NO];
        //头像
        self.headImageView = [UIImageView new];
        [self addSubview:self.headImageView];
        [self CreatNewImageView:self.headImageView imageName:@"porfile-img" radius:48 enabled:YES];
        
        //登录注册Label
        self.loginOrRegistLabel = [UILabel new];
        [self addSubview:self.loginOrRegistLabel];
        self.loginOrRegistLabel.userInteractionEnabled = YES;
        self.loginOrRegistLabel.font = Common_Font(15);
        self.loginOrRegistLabel.text = @"登录 / 注册";
        self.loginOrRegistLabel.textColor = Color.fullBtnTitle;
        
        UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(login)];
        [self addGestureRecognizer:tapGr];
    }
    return self;
}

-(void)CreatNewImageView:(UIImageView *)imageView imageName:(NSString *)imageName radius:(NSInteger)radius enabled:(BOOL)enabled{
    imageView.layer.cornerRadius = radius;
    imageView.layer.masksToBounds = YES;
    imageView.userInteractionEnabled = enabled;
    imageView.image = [UIImage imageNamed:imageName];
}

-(void)layoutSubviews{
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.mas_bottom).offset(-44);
        make.left.mas_equalTo(self.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.backImageView.mas_centerY);
        make.centerX.mas_equalTo(self.backImageView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(96, 96));
    }];
    [self.loginOrRegistLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.headImageView.mas_centerY);
        make.left.mas_equalTo(self.backImageView.mas_right).offset(15);
    }];
}

- (void)login{
    if ([self.delegate respondsToSelector:@selector(userChoose:)]) {
        [self.delegate userChoose:9999];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
